{% extends 'layout/layout.html' %}
{% import 'libs/libs.html' as libs %}
{% import 'libs/const.html' as const %}

{% block search_body %}
{%
    set form_config = [
        {'label':'按条件搜索', 'name':'search_type', 'type':'select',
            'options':[
                {'name':'姓名', 'value':'1'},
                {'name':'手机号码', 'value':'2'},
                {'name':'身份证号码', 'value':'3'},
            ]},
        {'label':'关键词', 'name':'keyword',},
        {'label':'学校', 'name':'school_name',},
        {'label':'导出', 'name':'is_export', 'type':'hidden'},
        {'label':'选取的id列表字符串', 'name':'id_list_str', 'type':'hidden'},
    ]
%}
{{ libs.build_search_form(form_config) }}

{% endblock %}
{% block data_body %}
{% set CERT_TYPE = {1:'护照', 2:'港澳通行证', 3:'护照、港澳通行证'}%}
<table class="table table-hover">
    <thead>
        <tr>
            <th>序号</th>
            <th>姓名</th>
            <th>性别</th>
            <th>手机号码</th>
        </tr>
    </thead>
    <tbody>
    {% for user in user_list %}
        <tr>
            <td>
                <div class="checkbox i-checks list-checkbox">
                    <div class="icheckbox_square-green">
                        <input name="data_check" type="checkbox" value="{{ user.uid }}" id="data_check">
                        <ins class="iCheck-helper"></ins>
                    </div> <i></i> {{ loop.index }}
                </div>
            </td>
            <td>{{ user.nickname }}</td>
            <td>{{ const.GENDER.get(user.gender, '') }}</td>
            <td>{{ user.mobile }}</td>
            <td>{{ user.add_time|format_timestamp }}</td>
        </tr>
    {% endfor %}
    </tbody>
</table>

{{ libs.pagination_html(pagination, is_row='false', all_check='yes') }}
{% endblock %}

{% block footer %}
<script type="text/javascript">
$("#add_new").click(function(){
    window.location.href = '/user/add';
});
$('input[name=data_check]').on('ifChecked', function(event){
    var id_list_str = $('#id_list_str').val();
    id_list_str += ',' +$(this).val();
    $('#id_list_str').val(id_list_str);
});
$('input[name=data_check]').on('ifUnchecked', function(event){
    var id_list_str = $('#id_list_str').val();
    id_list_str = id_list_str.replace(','+$(this).val(), "");
    $('#id_list_str').val(id_list_str);
});
$("#export_excel_button").click(function(){
    $("#is_export").val(1);
    document.getElementById("search_form").submit();
});
/**
function delete_user(uid, adom) {
    window.wxc.xcConfirm('确定要移除该会员吗？', window.wxc.xcConfirm.typeEnum.warning);
    $('a.sgBtn.ok').click(function() {
        $.get('/user/delete', {'uid':uid}, function(res){
            if (res != 'ok'){
                window.wxc.xcConfirm(res, window.wxc.xcConfirm.typeEnum.error);
                return false;
            }
            window.wxc.xcConfirm('移除成功！', window.wxc.xcConfirm.typeEnum.success);
            $(adom).parents('tr').remove();
            $count = $("a[href='javascript:;'].btn.btn-white").html()
            img_count = Number($count.slice(0, -1));
            if (img_count == 1){
                $('#pagination').html('暂无数据');
            }else{
                var img_count = img_count-1;
                $("a[href='javascript:;'].btn.btn-white").html(img_count+'条');
            }
            var t=setTimeout("$('a.sgBtn.ok').trigger('click')",900);
        });
    });
}
**/
var uid_id_str = $('#id_list_str').val();
if (uid_id_str == 'all') {
    $('#all_check').iCheck('check');
} else {
    $('input[name=data_check]').each(function(){
        var uid = $(this).val();
        if (uid_id_str.indexOf(uid+',') > -1 || uid_id_str.indexOf(','+uid) > -1) {
            $input.parents('.i-checks').iCheck('check');
        }
    });
};
</script>
{% endblock %}
